<template>
    <div>
        <div class="blog-area blog-grid-page">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-xl-8 col-lg-8">
                        <div class="section-title">
                            <h2>
                                热门保险
                            </h2>
                        </div>
                    </div>
                </div>
                <div class="row" style="display: flex; justify-content: center">
                    <div v-for="item in hots" class="col-xl-4 col-lg-4 col-md-6" v-bind:key="item">
                        <div class="single-blog">
                            <div v-if="item === 'AccidentInsurance'" @click="toDetail(3, 'AccidentInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/accident.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">E生平安 · 意外险</h3>
                                </div>
                            </div>
                            <div v-else-if="item === 'LifeInsurance'" @click="toDetail(0, 'LifeInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/support.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">E生平安 · 人寿险</h3>
                                </div>
                            </div>
                            <div v-else-if="item === 'EndowmentInsurance'" @click="toDetail(4, 'EndowmentInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/pension.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">养老无忧险</h3>
                                </div>
                            </div>
                            <div v-else-if="item === 'IllnessInsurance'" @click="toDetail(2, 'IllnessInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/illness.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">E生平安 · 重疾险</h3>
                                </div>
                            </div>
                            <div v-else @click="toDetail(1, 'EducationInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/education.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">教育保险</h3>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="blog-area blog-grid-page">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-xl-8 col-lg-8">
                        <div class="section-title">
                            <h2>
                                个人推荐
                            </h2>
                        </div>
                    </div>
                </div>
                <div class="row" style="display: flex; justify-content: center">
                    <div v-for="item in stays" class="col-xl-4 col-lg-4 col-md-6" v-bind:key="item">
                        <div class="single-blog">
                            <div v-if="item === 'AccidentInsurance'" @click="toDetail(3, 'AccidentInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/accident.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">E生平安 · 意外险</h3>
                                </div>
                            </div>
                            <div v-else-if="item === 'LifeInsurance'" @click="toDetail(0, 'LifeInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/support.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">E生平安 · 人寿险</h3>
                                </div>
                            </div>
                            <div v-else-if="item === 'EndowmentInsurance'" @click="toDetail(4, 'EndowmentInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/pension.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">养老无忧险</h3>
                                </div>
                            </div>
                            <div v-else-if="item === 'IllnessInsurance'" @click="toDetail(2, 'IllnessInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/illness.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">E生平安 · 重疾险</h3>
                                </div>
                            </div>
                            <div v-else @click="toDetail(1, 'EducationInsurance')">
                                <div class="part-img">
                                    <img src="../assets/img/home/education.jpg" alt="" slot="img">
                                </div>
                                <div class="part-text">
                                    <h3 slot="title">教育保险</h3>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
  export default {
    name: "Recommended",
    data() {
      return {
        hots: [],
        stays: [],
        insurances: []
      }
    },
    methods: {
      getInsurances() {
        this.$http.get('/insurance/index').then(res => {
          if (res.status === 200) {
            if (res.data.code === 200) {
              this.insurances = res.data.data
              this.$http.get('/user/behaviour_recommend').then(res => {  // hot
                console.log(res.data.recommend)
                res.data.recommend.forEach((item) => {
                  this.hots.push(item)
                })
              })
              this.$http.get('/user/visits_recommend').then(res => {
                console.log(res.data.recommend)
                res.data.recommend.forEach((item) => {
                  this.stays.push(item)
                })
              })
            } else {
              this.$Message.error(res.data.msg)
            }
          }
        }).catch(err => {
          this.$Message.error(err.toString())
        })
      },
      toDetail(index, name) {
        let detail = this.insurances[index]
        detail = detail[name]
        this.$router.push({
          path: '/insurance_details',
          query: {
            detail: detail,
            name: name
          }
        })
      }
    },
    created() {
      this.getInsurances()
    }
  }
</script>

<style scoped>

</style>